package io.nads.config;

import io.nads.api.impl.QiniuUploader;
import io.nads.api.impl.QiniuASR;
import io.nads.api.impl.QiniuTTS;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@ConfigurationProperties(prefix = "qiniu")
@Data
@RequiredArgsConstructor
public class QiniuConfig {
    private String accessKey;
    private String secretKey;
    private String bucketName;
    private Oss oss;
    private Asr asr;
    private Tts tts;

    private final StringRedisTemplate stringRedisTemplate;

    @Data
    public static class Oss {
        private String domain;
        private long tokenExpireInSeconds = 3600; // 默认1小时
    }

    @Data
    public static class Asr {
        private String baseUrl;
        private String apiKey;
    }

    @Data
    public static class Tts {
        private String baseUrl;
        private String apiKey;
        private Long voiceRedisExpireSeconds;
    }

    @Bean
    public QiniuUploader qiniuUploader() {
        return new QiniuUploader(accessKey, secretKey, bucketName, oss.getDomain(), oss.getTokenExpireInSeconds());
    }

    @Bean
    public QiniuASR qiniuASR() {
        return new QiniuASR(asr.getApiKey(), asr.getBaseUrl());
    }

    @Bean
    public QiniuTTS qiniuTTS() {
        return new QiniuTTS(tts.getApiKey(), tts.getBaseUrl());
    }
}
